package com.buttlever;

import com.ChessUtils.ChessUtil;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

/**
 * @author acoffee
 * @create 2021-09-01 12:20
 */
public class ConnectWindowView extends Stage {

    public ConnectWindowView() {

        setTitle("系统设置界面");

        //窗口不允许改变
        setResizable(false);

        //定义面板
        Pane pane = getPane();

        Scene scene = new Scene(pane, 400, 300);
        setScene(scene);

    }

    public Pane getPane() {


        //创建画板对象
        Pane pane = new Pane();

        ConnectWindowService connectWindow = new ConnectWindowService();

        //给画板对象设置背景颜色
        pane.setBackground(new Background(new BackgroundImage(new Image("/background.jpg"), null, null, null, null)));

        addBtnAndBox(pane, connectWindow);

        return pane;
    }

    public void addBtnAndBox(Pane pane, ConnectWindowService connectWindowService) {
        //4个输入框  2个按钮(确定/取消)
        TextField sourceIP = ChessUtil.getInputBox("请输入本端IP地址！", 110, 30);
        TextField sourcePort = ChessUtil.getInputBox("请输入本端端口号！", 110, 80);
        TextField targetIP = ChessUtil.getInputBox("请输入对端IP地址！", 110, 130);
        TextField targetPort = ChessUtil.getInputBox("请输入对对端端口号！", 110, 180);

        Label myLabelIp = ChessUtil.getBoxLabel("本端IP:", 40, 33);
        Label myLabelPort = ChessUtil.getBoxLabel("本端Port:", 40, 83);
        Label oppLabelIp = ChessUtil.getBoxLabel("对端IP:", 40, 133);
        Label oppLabelPort = ChessUtil.getBoxLabel("对端Port:", 40, 183);

        Button btnOk = ChessUtil.getButton("确 定", 60, 30, 110, 240);
        Button btnCancel = ChessUtil.getButton("取 消", 60, 30, 240, 240);

        connectWindowService.btnOkAction(this, btnOk, sourceIP, sourcePort, targetIP, targetPort);
        connectWindowService.btnCancelAction(btnCancel);

        pane.getChildren().addAll(sourceIP, sourcePort, targetIP, targetPort, btnOk, btnCancel, myLabelIp, myLabelPort, oppLabelIp, oppLabelPort);
    }

}
